using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class SkillupdatePanel : BasePanel
{
    static readonly string path = "UI/Panel/SkillupdatePanel";
    static readonly string skillpath = "UI/Skill/skill";
    static readonly string panelpath = "UI/SkillinPanel/";
    static readonly string playerpath = "UI/SkillinPlayer/";
    public SkillupdatePanel() : base(new UIType(path)) { }
    //private GameObject[] skillinpanel=new GameObject[4];
    //private GameObject[] skillinplayer=new GameObject[4];
    //string skillnames = new string[4];
    //string extranames = new string[4];
    //MonoBehaviour thispanel;
    int num = 0;
    private void skillchange(int num)
    {
        PlayerData.updatenamenum = num;
        if (PlayerData.extranames[num] == "000")
        {
            PlayerData.updateextranames[0] = "100";
            PlayerData.updateextranames[1] = "110";
        }
        else if(PlayerData.extranames[num] == "100")
        {
            PlayerData.updateextranames[0] = "200";
            PlayerData.updateextranames[1] = "201";

        }
        else
        {

            PlayerData.updateextranames[0] = "210";
            PlayerData.updateextranames[1] = "211";
        }
        panelmanager.PopAndPush(new SkillupdatePanel2());
    }
    public override void OnEnter()
    {
        for (int i = 0; i < 4; i++)
        {
            GameObject.Instantiate(Resources.Load<GameObject>(panelpath+ PlayerData.skillnames[i] + PlayerData.extranames[i]),GameObject.Find("skills").transform);
            if (PlayerData.extranames[i][0]=='2')
                uitool.GetOrAddComponentInChildren<Button>(PlayerData.skillnames[i] + PlayerData.extranames[i] + "(Clone)").enabled = false;
            Debug.Log(PlayerData.skillnames[i] + PlayerData.extranames[i]);
        }
            
        uitool.GetOrAddComponentInChildren<Button>(PlayerData.skillnames[0]+ PlayerData.extranames[0]+"(Clone)").onClick.AddListener(() =>
        {
            skillchange(0);


        });
        uitool.GetOrAddComponentInChildren<Button>(PlayerData.skillnames[1] + PlayerData.extranames[1] + "(Clone)").onClick.AddListener(() =>
        {
            skillchange(1);
        });
        uitool.GetOrAddComponentInChildren<Button>(PlayerData.skillnames[2] + PlayerData.extranames[2] + "(Clone)").onClick.AddListener(() =>
        {
            skillchange(2);
        });
        uitool.GetOrAddComponentInChildren<Button>(PlayerData.skillnames[3] + PlayerData.extranames[3] + "(Clone)").onClick.AddListener(() =>
        {
            skillchange(3);
        });
        uitool.GetOrAddComponentInChildren<Button>("return").onClick.AddListener(() =>
        {
            panelmanager.Pop();
        });
    }
}
